import axios from "axios";
import Toast from "/src/components/common/toast";

const httpClient = axios.create({
    baseURL: '/live'
});


export function get(params, callback) {
    let onSucc
    let onFail
    if (callback) {
        if (typeof callback === 'function') {
            onSucc = callback
        } else if (typeof callback === 'object') {
            onSucc = callback.onSucc
            onFail = callback.onFail
        }
    }
    httpClient.get('/appapi/', {params})
        .then(response => {
            if (onSucc) {
                const {code, msg, info} = response.data.data;
                onSucc(code, msg, info)
            }
        })
        .catch(error => {
            Toast.show('网络请求失败')
            if (onFail) {
                onFail(error);
            }
        })
}
